import Vue from 'vue'
import App from './App.vue'
import router from "./router/index"
// 引入vue-amap
import VueAMap from 'vue-amap'

import ElementUI from "element-ui"
import "element-ui/lib/theme-chalk/index.css"
import $ from "jquery"
import "jquery.easing"

import axios from 'axios'

import store from './store/store'

window.$ = $
window.jQuery = $
Vue.use(ElementUI)
Vue.config.productionTip = false
Vue.prototype.$axios = axios
Vue.use(VueAMap)

router.beforeEach((to, from, next) => {
  if(to.path === '/Organic/home' || to.path === '/Organic/login'|| to.path === '/Organic/registered' || to.path === '/' || to.path === ''|| to.path === '/login') {
    next();
    // eslint-disable-next-line no-empty
  }else if(store.getters.isLogin||store.getters.isSysLogin){
    let To = to.path.split('/')[1]
    console.log('to:', To);
    if(To === 'Organic'){
      if (store.getters.isLogin) {
        next();
      }else {
        next('/Organic/login');
      }
    }else if (To === 'backend') {
      if (store.getters.isSysLogin) {
        next();
      }else {
        next('/login');
      }
    }
  }else {
    console.log('Navigating from:', from.path, 'to:', to.path);
    console.log('Is user logged in?', store.getters.isLogin);
    let To = to.path.split('/')[1]
    if(To === 'Organic'){
      if (store.getters.isLogin) {
        next();
      }else {
        next('/Organic/login');
      }
    }else if (To === 'backend') {
      if (store.getters.isSysLogin) {
        next();
      }else {
        next('/login');
      }
    }
    // next('/Organic/login');
  }
})
// 初始化vue-amap
VueAMap.initAMapApiLoader({
  // 高德的key
  key: '88d64128fe21e2e90ece752222902741',
  // 插件集合
  plugin: [
    'AMap.CircleEditor',// 圆形编辑器插件
    "AMap.Geolocation", // 定位控件，用来获取和展示用户主机所在的经纬度位置
    "AMap.Geocoder", // 地理编码与逆地理编码服务，用于地址描述与坐标间的相互转换
    "AMap.Autocomplete",
    "AMap.PlaceSearch",
    "AMap.CitySearch",
    "AMap.Scale",
    "AMap.HawkEye",
    "AMap.ToolBar",
    "AMap.ControlBar",
    "AMap.MouseTool",
    "AMap.DragRoute",
    "AMap.MoveAnimation"
  ],
  // 高德 sdk 版本，默认为 1.4.4
  v: '1.4.4'
});
//高德的安全密钥
window._AMapSecurityConfig = {
  securityJsCode:'fba24bff6ea76006c57df197c46ef7b8',
}

new Vue({
  render: h => h(App),
  router,
  store
}).$mount('#app')
